#include <linux/types.h>

#include <linux/crypto.h>
#include <linux/err.h>
#include <linux/scatterlist.h>


MODULE_LICENSE( "GPL" );
MODULE_AUTHOR( "Vinson Yan <vinson.one.yan@gmail.com>" );


static void do_md5( void )
{
	struct scatterlist sg[2];
	char result[128];
	struct crypto_hash *tfm;
	struct hash_desc desc;

	tfm = crypto_alloc_hash( "md5", 0, CRYPTO_ALG_ASYNC );
	if ( IS_ERR( tfm ) ) {
		printk( "Alloc crypto hash failed.\n" );
		return ; 
	}

	/* ... set up the scatterlists ... */
	desc.tfm = tfm;
	desc.flags = 0;

	if ( crypto_hash_digest( &desc, sg, 2, result ) ) {
		printk( "Digest hash failed.\n" );
		return ;
	}

	printk( "result [ %s ].\n", result );

	crypto_free_hash(tfm); 
	
	return ;
}

static int __init md5_test_init( void )
{
	do_md5();

	return 0;	
}

static void __exit md5_test_exit( void )
{
	return ;
}

module_init( md5_test_init );
module_exit( md5_test_exit );
